package com.qjcc.service.impl;

import com.qjcc.config.MyWebSocket;
import com.qjcc.service.CallCenterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

@Component
@Configurable
@EnableScheduling
public class ScheduledTasks {

    @Autowired
    private CallCenterService callCenterService;

    //每30S执行一次
    @Scheduled(cron = "*/30 * * * * *")
    public void reportCurrentByCron(){
        System.out.println ("Scheduling Tasks Examples By Cron: The time is now " + dateFormat ().format (new Date()));
        String result = callCenterService.queryPmd();
        System.out.println("Scheduling Tasks result:" + result);
        try {
            MyWebSocket.sendInfo(result);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private SimpleDateFormat dateFormat(){
        return new SimpleDateFormat("HH:mm:ss");
    }

    public static void main(String[] args) {
        String st = "打法的萨芬，";
        System.out.println(st.substring(0, st.length() - 1));
    }

}
